package book.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCUtils {
	public static Connection getConnection() throws SQLException,ClassNotFoundException
	{
	Class.forName("com.mysql.jdbc.Driver");
	String url = "jdbc:mysql://localhost:3306/sy5";
	String username = "root";
	String password = "root";
	Connection conn = DriverManager.getConnection(url, username, password);
	return conn;
	}
	public static void release(ResultSet rs, Statement stmt, Connection conn) {
		if (rs!=null) 
			try{
				rs.close();
			}catch (SQLException e2) {
				// TODO: handle exception
				e2.printStackTrace();
			}
			rs=null;
			if (stmt!=null) 
				try{
					stmt.close();
				}catch (SQLException e2) {
					// TODO: handle exception
					e2.printStackTrace();
				}
				stmt=null;
			if (conn!=null) 
					try{
						conn.close();
					}catch (SQLException e2) {
						// TODO: handle exception
						e2.printStackTrace();
					}
					conn=null;
		}
		
	}

